package com.estate.web.controller.system;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.estate.common.core.controller.BaseController;
import com.estate.common.core.domain.AjaxResult;
import com.estate.common.core.page.TableDataInfo;
import com.estate.system.domain.MessageSendToClient;
import com.estate.system.domain.pojo.*;
import com.estate.system.service.IClientRequirementService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 用户信息
 *
 * @author ruoyi
 */
@RestController
@RequestMapping("/client/requirement")
public class ClientRequirementController extends BaseController {

    @Resource
    private IClientRequirementService clientRequirementService;

    @ApiOperation(value = "查询客户详情（分页）")
    @GetMapping(value = "/pages")
    public TableDataInfo clientRequirementsPages(ClientRequirementVo clientRequirementVo) {
        startPage();
        Page<ClientRequirementVo> list = clientRequirementService.clientRequirementsPages(clientRequirementVo);
        return getDataTable(list);

    }

    @ApiOperation(value = "查询推荐房源详情（分页）")
    @GetMapping(value = "/recommendations/pages/{clientId}")
    public TableDataInfo clientRecommendationsPages(ClientRecommendationsVo clientRecommendationsVo) {
        startPage();
        Page<ClientRecommendationsVo> list = clientRequirementService.clientRecommendationsPages(clientRecommendationsVo);
        return getDataTable(list);

    }

    @ApiOperation(value = "查询感兴趣房源详情（分页）")
    @GetMapping(value = "/interested/pages")
    public TableDataInfo clientInterestedPages(ClientInterestedVo clientInterestedVo) {
        startPage();
        Page<ClientInterestedVo> list = clientRequirementService.clientInterestedPages(clientInterestedVo);
        return getDataTable(list);

    }

    @ApiOperation(value = "生成邮件信息")
    @PostMapping(value = "/generate/message")
    public AjaxResult generateMessage(@RequestBody List<GenerateMessageVo> clientInterestedVos) {
        List<MessageSendToClient> messageList = clientRequirementService.generateMessage(clientInterestedVos);
        return AjaxResult.success(messageList);

    }

    @ApiOperation(value = "暂存邮件信息")
    @PostMapping(value = "/save/draft/message")
    public AjaxResult saveDraftMessage(@RequestBody List<Message2AddrVo> messageList) {
        List<MessageSendToClient> messageSendToClients = clientRequirementService.saveDraftMessage(messageList);
        return AjaxResult.success(messageSendToClients);

    }

    @ApiOperation(value = "查询暂存邮件信息")
    @PostMapping(value = "/get/draft/message")
    public AjaxResult getDraftMessage(@RequestBody List<Long> sendMessageIds) {
        List<Message2AddrVo> message2AddrVos = clientRequirementService.getDraftMessage(sendMessageIds);
        return AjaxResult.success(message2AddrVos);

    }

    @ApiOperation(value = "发送信息")
    @PostMapping(value = "/send/message")
    public AjaxResult sendMessage(@RequestBody List<Message2AddrVo> message2AddrVos) {
        Map<String, Object> messageList = clientRequirementService.sendMessage(message2AddrVos);
        return AjaxResult.success(messageList);

    }

    @ApiOperation(value = "联系记录")
    @GetMapping(value = "/contact/record/{clientId}")
    public AjaxResult clientContactRecord(@PathVariable("clientId") Long clientId) {
        List<MessageSendToClient> list = clientRequirementService.clientContactRecord(clientId);
        return AjaxResult.success(list);

    }
}
